package com.rem.cloudalibaba.service;

import com.rem.cloudalibaba.entity.CommonResult;
import com.rem.cloudalibaba.entity.Product;
import com.rem.cloudalibaba.service.fallback.ProductServiceFallBackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * 需要声明被调用方的serviceName
 *
 * @author Rem
 * @date 2021-07-15
 */
@Service
@FeignClient(value = "provider-product",
        // 异常处理方法和工厂处理的事情是一样， 只能选择一个
        // fallback = ProductServiceFallback.class,
        fallbackFactory = ProductServiceFallBackFactory.class)
public interface ProductService {


    /**
     * 指定调用的方法
     *
     * @param id
     * @return
     * @FeignClient+@GetMapping 就是一个完整的请求路径 http://provider-product/product/getProduct/{id};
     */
    @GetMapping("/product/getProduct/{id}")
    CommonResult<Product> getProduct(@PathVariable("id") Integer id);

    /**
     * 扣减库存 返回商品详情
     *
     * @param id
     * @param num
     * @return
     */
    @PostMapping("/product/redStock/{id}/{num}")
    CommonResult<Product> redStock(@PathVariable("id") Integer id, @PathVariable("num") Integer num);


    @GetMapping("/product/test/{id}")
    CommonResult<String> test(@PathVariable("id") Integer id);

}
